import type { 
  ICrud, 
  AsyncVoid,
  AsyncDataResult,
  InsertRecordParams,
  DeleteRecordParams,
  UpdateRecordParams
} from '../../types'
import { HttpClient } from '../../HttpClient'

export class CrudAPI implements ICrud {
  private httpClient: HttpClient

  constructor(httpClient: HttpClient) {
    this.httpClient = httpClient
  }

  public async insert(params: InsertRecordParams): AsyncVoid {
    return await this.httpClient.request<InsertRecordParams, void>('insert_record', params)
  }

  public async update(params: UpdateRecordParams): AsyncVoid {
    return await this.httpClient.request<UpdateRecordParams, void>('update_record', params)
  }

  public async drop(params: DeleteRecordParams): AsyncDataResult<string> {
    return await this.httpClient.request<DeleteRecordParams, string>('delete_record', params)
  }
}
